package com.daigoudao.system;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.daigoudao.util.SequenceUtil;
import com.daigoudao.web.service.ITransInfoService;

public class SequenceListener implements ServletContextListener {

	@Override
	public void contextDestroyed(ServletContextEvent arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void contextInitialized(ServletContextEvent sce) {
		WebApplicationContext wac = WebApplicationContextUtils
				.getWebApplicationContext(sce.getServletContext());
		ITransInfoService transInfoService = (ITransInfoService) wac
				.getBean("transInfoService");
		try {
			SequenceUtil.init(transInfoService.getLastTransId());
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("init last trans id error.");
			System.exit(-1);
		}

	}
}
